package com.xinzhi.savingpot.userinfo.controller;

import com.xinzhi.savingpot.userinfo.service.impl.HistoricalProblemServiceImpl;
import com.xinzhi.savingpot.util.BaseResponse;

import com.xinzhi.savingpot.util.JwtUtil;
import com.xinzhi.savingpot.vo.HistoricalProblemVo;
import io.jsonwebtoken.Claims;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping("problem")
@Api
@CrossOrigin
public class HistoricalProblemController {
    @Autowired
    private HistoricalProblemServiceImpl historicalProblemService;


    @GetMapping("/submit")
    @ApiOperation("提交未解决问题")
    public BaseResponse insertinto(@RequestParam("meetproblem") String meetproblem, @RequestParam("problem_description") String problem_description, @RequestParam("photo") String photo, @RequestParam("cyphone") String cyphone, @RequestParam("QQ") String qq, HttpServletRequest request){
        //解析token获取头部userid
        String token = request.getHeader("token");
        Claims claims = JwtUtil.checkJWT(token);
        String jxuserid = claims.getAudience();

        HistoricalProblemVo historicalProblemVo = new HistoricalProblemVo();
        historicalProblemVo.setMeetproblem(meetproblem);
        historicalProblemVo.setProblem_description(problem_description);
        historicalProblemVo.setCyphone(cyphone);
        historicalProblemVo.setPhoto(photo);
        historicalProblemVo.setQQ(qq);
        historicalProblemVo.setUserNumber(Integer.parseInt(jxuserid));
       return historicalProblemService.add(historicalProblemVo);
    }

    @GetMapping("select")
    @ApiOperation("查看历史提交问题和发布时间")
    public BaseResponse xixi (HttpServletRequest request){
        String token = request.getHeader("token");
        Claims claims = JwtUtil.checkJWT(token);
        String jxuserid = claims.getAudience();

        return historicalProblemService.chaxun(Integer.parseInt(jxuserid));

    }

}
